/*
 * Copyright (C) 2009 Internal Innovation Technology(IIT)
 * 
 */
package com.iitbd.hxcalc;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFileChooser;
import org.supercsv.io.CsvListReader;

/**
 *
 * @author Prasun Kanti Howlader <prasun@iitbd.com>
 */
public class FileOutputDialog extends javax.swing.JDialog {

    private HxcalcUI parent = null;
    CsvListReader parser = null;
     List<String> values = new ArrayList<String>();

    /**
     * Creates new form FileInputDialog
     */
    public FileOutputDialog(javax.swing.JFrame parent, String title) {
        super(parent, title);
        this.parent = (HxcalcUI) parent;
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btgSepataor = new javax.swing.ButtonGroup();
        btgDecimal = new javax.swing.ButtonGroup();
        btnExit = new javax.swing.JButton();
        lbMessage = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        rdTab = new javax.swing.JRadioButton();
        cmbFile = new javax.swing.JComboBox();
        rdSemicolon = new javax.swing.JRadioButton();
        jLabel3 = new javax.swing.JLabel();
        rdDot = new javax.swing.JRadioButton();
        rdComma = new javax.swing.JRadioButton();
        jLabel4 = new javax.swing.JLabel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setModal(true);
        setResizable(false);

        btnExit.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        btnExit.setText(Resources.getString("Output.Save"));
        btnExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExitActionPerformed(evt);
            }
        });

        lbMessage.setFont(new java.awt.Font("Dialog", 1, 12)); // NOI18N
        lbMessage.setForeground(java.awt.Color.red);

        jLabel1.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        jLabel1.setText(Resources.getString("File Name"));

        jLabel2.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        jLabel2.setText(Resources.getString("Separator"));

        btgSepataor.add(rdTab);
        rdTab.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        rdTab.setText(Resources.getString("Tab"));

        cmbFile.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        cmbFile.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "test" }));
        cmbFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbFileActionPerformed(evt);
            }
        });

        btgSepataor.add(rdSemicolon);
        rdSemicolon.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        rdSemicolon.setText(Resources.getString("Semicolon"));

        jLabel3.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        jLabel3.setText(Resources.getString("Decimal"));

        btgDecimal.add(rdDot);
        rdDot.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        rdDot.setText(Resources.getString("Dot"));

        btgDecimal.add(rdComma);
        rdComma.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        rdComma.setText(Resources.getString("Comma"));

        jLabel4.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        jLabel4.setText(Resources.getString("Output.SaveAll"));

        jCheckBox1.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N

        jLabel5.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        jLabel5.setText(Resources.getString("Output File"));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lbMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnExit))
                    .addComponent(jLabel5)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGap(44, 44, 44)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBox1)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(rdDot, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(rdTab, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(rdSemicolon, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE)
                                        .addComponent(rdComma, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
                                .addComponent(cmbFile, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(38, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cmbFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(jLabel2))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(rdSemicolon)
                        .addComponent(rdTab)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(15, 15, 15)
                        .addComponent(jLabel3)
                        .addGap(11, 11, 11)
                        .addComponent(jLabel4))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(rdComma)
                            .addComponent(rdDot))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCheckBox1)))
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnExit)
                    .addComponent(lbMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExitActionPerformed
        dispose();//Releases all of the native screen resources used by this Window        
    }//GEN-LAST:event_btnExitActionPerformed
    
    private void cmbFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbFileActionPerformed
        JFileChooser chooser = new JFileChooser();
        int returnVal = chooser.showSaveDialog(parent);
        File filename = chooser.getSelectedFile();
        if (HxCalc.instance.getUtils().getFileName() == null) {
            HxCalc.instance.getUtils().setFileName(filename);
            //cmbFile.setModel(new javax.swing.DefaultComboBoxModel(new String[]{filename.getAbsolutePath()}));
             cmbFile.setModel(new javax.swing.DefaultComboBoxModel(new String[]{filename.getName()}));
             cmbFile.setToolTipText(filename.getAbsolutePath());
            //readCSV();
        } else {
            lbMessage.setText(Resources.getString("Output.message"));
        }
    }//GEN-LAST:event_cmbFileActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup btgDecimal;
    private javax.swing.ButtonGroup btgSepataor;
    private javax.swing.JButton btnExit;
    private javax.swing.JComboBox cmbFile;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel lbMessage;
    private javax.swing.JRadioButton rdComma;
    private javax.swing.JRadioButton rdDot;
    private javax.swing.JRadioButton rdSemicolon;
    private javax.swing.JRadioButton rdTab;
    // End of variables declaration//GEN-END:variables
}
